<template>
  <ul class="list">
    <li
      class="item"
      v-for="item in letters"
      :key="item"
      :ref="item"
      @touchStart="handleTouchStart"
      @touchMove="handleTouchMove"
      @touchEnd="handleTouchEnd"
      @click="handleClickLetter"
    >
      {{ item }}
    </li>
  </ul>
</template>

<script>
export default {
  name: "CityAlphabet",
  props: {
    cities: Object,
    letter: String,
  },
  data() {
    return {
      touchStatus: false,
    };
  },
  computed: {
    letters() {
      const letters = [];
      for (const i in this.cities) {
        letters.push(i);
      }
      return letters;
    },
  },
  methods: {
    handleClickLetter(e) {
      this.$emit("change", e.target.innerText);
    },
    handleTouchStart() {
      this.touchStatus = true;
    },
    handleTouchMove(e) {
      if (this.touchStatus) {
        const startY = this.$refs["A"][0].offSetTop;
        const touchY = e.touches[0].clientY - 60;
        const index = Math.floor((touchY - startY) / 12);
        console.log(index);
      }
    },
    handleTouchEnd() {
      this.touchStatus = false;
    },
  },
};
</script>

<style lang="stylus" scoped>
.list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: absolute;
  top: 2.85rem;
  right: 0;
  bottom: 0;
  width: 0.8rem;
}

.item {
  color: #00bcd4;
  margin: 0.1rem;
}
</style>